package com.alibaba.cola.demo.common;

import com.alibaba.cola.core.dto.Response;

import java.util.UUID;

public class Result<T> extends Response {

    private String requestId = UUID.randomUUID().toString();
    private int code;
    private String message;
    private long time = System.currentTimeMillis();
    private T data;

    public Result() {

    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(ResultMessage resultMessage) {
        this.code = resultMessage.getCode();
        this.message = resultMessage.getMessage();
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(ResultMessage resultMessage, T data) {
        this.code = resultMessage.getCode();
        this.message = resultMessage.getMessage();
        this.data = data;
    }

    public static <T> Result<T> SUCCESS() {
        return new Result<>(ResultMessage.SUCCESS);
    }

    public static <T> Result<T> SUCCESS(T data) {
        return new Result<>(ResultMessage.SUCCESS, data);
    }

    public static <T> Result<T> FAIL() {
        return new Result<>(ResultMessage.FAIL);
    }

    public static <T> Result<T> FAIL(int code, String message) {
        return new Result<>(code, message);
    }

    public static <T> Result<T> SUCCESS(ResultMessage resultMessage) {
        return new Result<>(resultMessage.getCode(), resultMessage.getMessage());
    }

    public static <T> Result<T> SUCCESS(ResultMessage resultMessage, T data) {
        return new Result<T>(resultMessage.getCode(), resultMessage.getMessage(), data);
    }

    public static <T> Result<T> FAIL(ResultMessage resultMessage) {
        return new Result<>(resultMessage.getCode(), resultMessage.getMessage());
    }

    public static <T> Result<T> FAIL(ResultMessage resultMessage, T data) {
        return new Result<T>(resultMessage.getCode(), resultMessage.getMessage(), data);
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
